Skip to main content

yCheckbox

Description

The yCheckbox is an essential user interface element that allows users to make binary choices or toggle between two states. It's commonly used in forms, settings, and wherever a selection is needed. Usecases can be:

Basic Structure

The basic structure of yCheckbox includes a checkbox icon and an optional label that describes its purpose.

@note Image

Label

The label is an optional text placed next to the checkbox, providing information about the choice it represents. It can be positioned on either side of the checkbox, depending on the layout requirements.

Box

The box represents the clickable area of the yCheckbox, showing an indicator when selected. It can be customized in terms of color, size, and border to match the application's design theme.

Properties

Through its various properties the yCheckbox can be configured to suit your needs. The display below provides you with an overview of all the yCheckbox properties.

Properties can be changed directly through three methods:

  • Inside the Toolbar, which is positioned in your workarea next to your component where you need it. It shows the most important properties, thus providing a fast and efficient way to configure your component in the most basic way.
  • It may also occur in the Toolbar Extension, which is a seamless extension accesible as a dropdown item of the Toolbar. It extends the functionality of the Toolbar by providing advanced pickers for most used properties.
  • Inside the Detail Panel, which is located in the righthand drawer. Every property of a component can be configured here.
METAread more
--y-checkbox__component-id

The identifier of the component that is unique within a page.

--y-checkbox__component-type

The type of the component. For this component it is -checkbox.

--y-checkbox__name

The custom name of the component. It serves for better identification of the component.

--y-checkbox__version

The custom version of the Checkbox-component. This can be used to ensure that all components work well together.

--y-checkbox__core-theme

The CoreTheme, which will be apllied to the Checkbox. For further information on themes visit the themes page.

--y-checkbox__sub-theme

The subtheme subordinated to the previously specified CoreTheme, which will be apllied to the Checkbox. For further information on themes visit the themes page.

--y-checkbox__group-theme

The group theme is a further variation of the subtheme which is specified especially for variations of a component inside the subtheme. For further information on themes visit the Theme-Manager page.

DISPLAYread more
--y-checkbox__display

This property specifies the display behavior of the component. This can be be set to:

  • none
  • block
  • flex
  • inline
--y-checkbox__position

This property specifies the type of positioning method used for the component. This can be be set to:

  • static
  • relative
  • absolute
  • sticky
  • fixed
--y-checkbox__visible

This property can toggle the visibility of the component. The two modes are completely hidden and fully shown.

SIZEread more
--y-checkbox__min-width

The minimum value for the width of the component. This can be set in:

  • px
  • pt
  • em
  • vw
  • vh
  • %
--y-checkbox__min-height

The minimum value for the height of the component. This can be set in:

  • px
  • pt
  • em
  • vw
  • vh
  • %
--y-checkbox__width

The value for the width of the component. This can be set in:

  • px
  • pt
  • em
  • vw
  • vh
  • %
  • auto
--y-checkbox__height

The value for the height of the component. This can be set in:

  • px
  • pt
  • em
  • vw
  • vh
  • %
  • auto
--y-checkbox__max-width

The maximum value for the width of the component. This can be set in:

  • px
  • pt
  • em
  • vw
  • vh
  • %
  • none
--y-checkbox__max-height

The maximum value for the height of the component. This can be set in:

  • px
  • pt
  • em
  • vw
  • vh
  • %
  • none
--y-checkbox__flex

The flex property sets the length on flexible items. This sets the value in n-fold shares extrapolated to all other components with the flex display within the same container.

PLACEMENTread more
--y-checkbox__margin-top

This property creates a space around the component, outside of the top border. This can be set in percent or pixels.

--y-checkbox__margin-right

This property creates a space around the component, outside of the right border. This can be set in percent or pixels.

--y-checkbox__margin-bottom

This property creates a space around the component, outside of the bottom border. This can be set in percent or pixels.

--y-checkbox__margin-left

This property creates a space around the component, outside of the left border. This can be set in percent or pixels.

--y-checkbox__padding-top

This property creates a space within the component, inside of the top border. This can be set in percent or pixels.

--y-checkbox__padding-right

This property creates a space within the component, inside of the right border. This can be set in percent or pixels.

--y-checkbox__padding-bottom

This property creates a space within the component, inside of the bottom border. This can be set in percent or pixels.

--y-checkbox__padding-left

This property creates a space within the component, inside of the top border. This can be set in percent or pixels.

Usage

In this section you'll find a collection of application scenarios and examples that illustrate how to leverage the yCheckbox in ways that deviate from its standard behavior, as defined by yBase. This section aims to inspire and guide you through various possibilities, helping you to implement more complex or unique functionalities tailored to your specific needs. General properties that are universally applicable can be found in the yBase usage section.

Variations

Checkbox Elevated
Checkbox Flat
Checkbox Outlined
Checkbox Rounded
Checkbox Plain
genericsizeminWidth95px
genericsizemaxHeight30px
stylebackgroundbgColor__normal#44ddbb
styleshadowboxShadow__normal0 3px 6px 0 rgba(16, 18, 24, 0.2)
styleborderborderRadius8px
stylelabellabel__fontColor__normal#FFFFFF
styleboxboxOff__bgColor#FFFFFF
styleboxboxOff__borderColor#FFFFFF
styleboxboxOn__bgColor#FFFFFF
styleboxboxOn__borderColor#FFFFFF
styleboxboxOn__iconColor#44ddbb

Custom Style Variations

Configure your yCheckbox with unique styles to emphasize their importance or to better integrate with your application's design.

Checkbox Standard
Checkbox Dark Mode
genericsizeminWidth200px
styleboxboxOff__bgColor#FFFFFF
styleboxboxOff__borderColor#767676
styleboxboxOn__bgColor#4A90E2
styleboxboxOn__borderColor#4A90E2
styleboxboxOn__iconColor#FFFFFF
stylelabellabel__fontColor#333333
stylelabellabel'Standard Checkbox'

Setting the Checkbox Value

The yCheckbox component's value can be dynamically assigned either programmatically via JavaScript or by establishing a link to another component's value—known as a SourceLink. This flexibility allows the yCheckbox to respond to user interactions or application states in real time.

Via JavaScript

To set the yCheckbox's value using JavaScript, access the value property within the "style" > "thumb" category. This method is ideal for changing the yCheckbox's state based on user interactions or other events within your application.

Here’s how you can set the value in JavaScript:

EvtClicked
// function onCheckbox_1_EvtClicked (apiObject, component, eventData) {
var desiredValue = true; // or false
component.set("style", "thumb", "value", desiredValue);
// }

Simply replace desiredValue with the appropriate boolean or comparable value that corresponds to the yCheckbox's position.

To link the yCheckbox’s value with another component (e.g. another yCheckbox), use the SourceLink Picker. This feature binds the yCheckbox’s state to another component's value, allowing for integrated component behavior.

How to:

  1. Create another yCheckbox component in your application.
  2. Select the created yCheckbox and open the Detail Panel.
  3. Within these settings, proceed to the "Links" section and open "value".
  4. Create a new SourceLink -> select the other yCheckbox you just created and choose "value" as an event.

Now each time you trigger the second yCheckbox, the first one will also be triggered. To make this both ways you have to repeat this process for the other yCheckbox as well.

Alternatively you can use the SourceLink Picker in the Toolbar as a Toolbar Extension.

Setting Error States

Use the yCheckbox to provide immediate feedback on form validations by setting an error state.

yButton:EvtChanged
// Example: Validate Checkbox State
// function onButton_1_EvtClicked (apiObject, component, eventData) {

leet checkboxComponent = apiObject.ui.getObject(checkboxId);
const isChecked = checkboxComponent.get("style", "box", "value");

if (!isChecked) {
// Set error state and message
checkboxComponent.set("component", "error", "error", true);
checkboxComponent.set("component", "error", "errorMessage", "This field is required.");
} else {
// Clear error state
checkboxComponent.set("component", "error", "error", false);
}
//}

Integration with Other Components

The yCheckbox can interact with other components, enabling or disabling functionalities based on its state. This behavior is essential for creating dynamic forms and interfaces.

Checkbox EvtClicked
// Example: Toggle visibility of another component based on checkbox state
// function onCheckbox_1_EvtClicked (apiObject, component, eventData) {

const isChecked = eventData.data;
let targetComponentId = 2;
let targetComponentType = "y-input";

const targetComponent = apiObject.ui.getObject(
targetComponentId,
targetComponentType
);

if (isChecked) {
targetComponent.set("generic", "display", "visible", "visible");
} else {
targetComponent.set("generic", "display", "visible", "hidden");
}

//}